package so.sao.code.service.web.portal;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import so.sao.code.service.domain.entity.EnterpriseDomain;
import so.sao.code.service.service.EnterpriseDomainService;

@Api(tags = "enterpriseDomain", description = "企业域名管理")
@RestController
@RequestMapping("portal/enterpriseDomain")
public class EnterpriseDomainController {

	@Autowired
	private EnterpriseDomainService enterpriseDomainService;

	@ApiOperation(value = "获取企业域名列表接口", notes = "依据企业id和状态查询企业域名列表（用于创建标签批次），Feign调用EnterpriseClient的findDomainByEseIdAndStatus方法")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "eseId", value = "企业ID", required = true, dataType = "Long", paramType = "query"),
			@ApiImplicitParam(name = "status", value = "状态:0、有效，1、无效", required = true, dataType = "Integer", paramType = "query") })
	@GetMapping(value = "/{eseId}/{status}")
	@RequiresAuthentication
	public List<EnterpriseDomain> findByEseId(@PathVariable Long eseId, @PathVariable Integer status) {
		return enterpriseDomainService.findByEseId(eseId);
	}

	@ApiOperation(value = "保存企业域名列表接口", notes = "保存企业域名信息，Feign调用EnterpriseClient的saveDomain方法")
	@ApiImplicitParam(name = "companyDomain", value = "企业域名信息", dataType = "EnterpriseDomain", paramType = "body")
	@PostMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequiresAuthentication
	public EnterpriseDomain create(@RequestBody EnterpriseDomain companyDomain) {
		return enterpriseDomainService.save(companyDomain);
	}

	@ApiOperation(value = "修改企业域名接口", notes = "修改企业域名信息，Feign调用EnterpriseClient的updateDomain方法")
	@ApiImplicitParam(name = "companyDomain", value = "企业域名信息", dataType = "EnterpriseDomain", paramType = "body")
	@PutMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequiresAuthentication
	public EnterpriseDomain update(@RequestBody EnterpriseDomain companyDomain) {
		return enterpriseDomainService.update(companyDomain);
	}
}
